package com.all.play.myapplication.fragment;

import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;

import com.all.play.myapplication.R;
import com.all.play.myapplication.adapter.AdapterVideoList;
import com.all.play.myapplication.base.BaseFragment;
import com.all.play.myapplication.utils.VideoConstant;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.jzvd.JZVideoPlayer;

/**
 * Created by 聪明一只哈 on 2018/4/18.
 * Time: 2018/4/18  15:02
 */

public class ProductFragment extends BaseFragment {

    private String videoUrl = "http://gslb.miaopai.com/stream/ed5HCfnhovu3tyIQAiv60Q__.mp4";


    @BindView(R.id.listview)
    ListView listview;
    Unbinder unbinder;

    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.fragment_product, null);
        unbinder = ButterKnife.bind(this, view);


        return view;
    }

    @Override
    public void initData() {
        super.initData();
        listview.setAdapter(new AdapterVideoList(getActivity(),
                VideoConstant.videoUrls[0],
                VideoConstant.videoTitles[0],
                VideoConstant.videoThumbs[0]));


        listview.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                JZVideoPlayer.onScrollReleaseAllVideos(view, firstVisibleItem, visibleItemCount, totalItemCount);
            }
        });


    }

    @Override
    public void onPause() {
        super.onPause();
        JZVideoPlayer.releaseAllVideos();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
